package com.example.deertrip;


import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;

import com.example.deertrip.bean.Flight;
import com.example.deertrip.bean.Moment;
import com.example.deertrip.bean.Tb_HotelInfo;
import com.example.deertrip.bean.Tb_HotelReserve;
import com.example.deertrip.database.DBOperate;
import com.google.android.material.bottomnavigation.BottomNavigationView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;
import androidx.navigation.ui.AppBarConfiguration;
import androidx.navigation.ui.NavigationUI;

import com.example.deertrip.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding binding;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        binding = ActivityMainBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());



        login_stateinit();
        BottomNavigationView navView = findViewById(R.id.nav_view);
        // Passing each menu ID as a set of Ids because each
        // menu should be considered as top level destinations.
        AppBarConfiguration appBarConfiguration = new AppBarConfiguration.Builder(
                R.id.navigation_home, R.id.navigation_soceity, R.id.navigation_my)
                .build();
        NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment_activity_main);
        NavigationUI.setupActionBarWithNavController(this, navController, appBarConfiguration);
        NavigationUI.setupWithNavController(binding.navView, navController);

        Bundle bundle = getIntent().getBundleExtra("bundle");

    }

    private void login_stateinit() {
        SharedPreferences sp=getSharedPreferences("deertrip",MODE_PRIVATE);
        SharedPreferences.Editor editor=sp.edit();

        int loginstate=sp.getInt("login_state",99);
        if(loginstate==99) {
            editor.putInt("login_state", 0);
            editor.commit();
        }

        int sqlstate=sp.getInt("sqlstate",99);
        if(sqlstate==99) {
             editor.putInt("sqlstate",1);
             editor.commit();
            sqlload();
        }
    }

    public  void sqlload(){
        DBOperate dbOperate=new DBOperate(this);

        Bitmap hotelimage = BitmapFactory.decodeResource(this.getResources(),R.mipmap.hotelpic);
        Bitmap hotelimage1 = BitmapFactory.decodeResource(this.getResources(),R.mipmap.hotelpic2);
        Bitmap hotelimage2 = BitmapFactory.decodeResource(this.getResources(),R.drawable.hotelpic3);
        Bitmap hotelimage3 = BitmapFactory.decodeResource(this.getResources(),R.drawable.hotelpic4);
        Bitmap hotelimage4 = BitmapFactory.decodeResource(this.getResources(),R.drawable.hotelpic5);

        Bitmap gimage = BitmapFactory.decodeResource(this.getResources(),R.drawable.guohang);
        Bitmap ximage= BitmapFactory.decodeResource(this.getResources(),R.drawable.xiahang);
        Bitmap shandong= BitmapFactory.decodeResource(this.getResources(),R.drawable.shandong);
        Bitmap nanfang= BitmapFactory.decodeResource(this.getResources(),R.drawable.nanfang);
        Bitmap beifang= BitmapFactory.decodeResource(this.getResources(),R.drawable.beifang);
        //酒店数据库
        Tb_HotelInfo htinfo=new Tb_HotelInfo(123456789L,"羊舍酒店",hotelimage,"羊羊大世界1号","5.0");
        Tb_HotelInfo htinfo3=new Tb_HotelInfo(153886446L,"渣渣酒店",hotelimage2,"渣渣街1号","4.1");
        Tb_HotelInfo htinfo4=new Tb_HotelInfo(198745842L,"民国酒店",hotelimage3,"民国城区上海路1号","3.7");
        Tb_HotelInfo htinfo2=new Tb_HotelInfo(456789351L,"嘤嘤精品酒店",hotelimage4,"嘤嘤佬皮大世界6号","4.2");
        Tb_HotelInfo htinfo1=new Tb_HotelInfo(987654321L,"维也纳酒店",hotelimage1,"大连甘井子2号","3.1");


        Flight flight1=new Flight(6006,"12:20","头等舱",699,"中国航空","00:30","10.1h","北京","美国",gimage);
        Flight flight2=new Flight(7007,"11:20","经济舱",899,"厦门航空","12:30","1.1h","厦门","上海",ximage);
        Flight flight5=new Flight(200,"1:20","经济舱",1020,"北方航空","4:30","3.1h","大连","福建",beifang);
        Flight flight4=new Flight(10086,"13:15","经济舱",100,"山东航空","14:15","1.0h","海南","新疆",shandong);
        Flight flight3=new Flight(12350,"3:00","经济舱",856,"南方航空","7:00","4.0h","宁夏","长沙",nanfang);
        dbOperate.saveHotelInfo(htinfo);
        dbOperate.saveHotelInfo(htinfo1);
        dbOperate.saveHotelInfo(htinfo3);
        dbOperate.saveHotelInfo(htinfo4);
        dbOperate.saveHotelInfo(htinfo2);

        dbOperate.saveFlight(flight1);
        dbOperate.saveFlight(flight2);
        dbOperate.saveFlight(flight3);
        dbOperate.saveFlight(flight4);
        dbOperate.saveFlight(flight5);
        Bitmap zyimage = BitmapFactory.decodeResource(this.getResources(),R.drawable.deer);
        Bitmap zzhimage= BitmapFactory.decodeResource(this.getResources(),R.drawable.zzh);
        Bitmap wwzimage=BitmapFactory.decodeResource(this.getResources(),R.drawable.wwzimage);
        Bitmap wwzhs=BitmapFactory.decodeResource(this.getResources(),R.drawable.yyhs);
        Bitmap mr=BitmapFactory.decodeResource(this.getResources(),R.drawable.mr);
        Moment moment1=new Moment("鹿途旅行太好了！","张炸毁",1,zzhimage);
        Moment moment2=new Moment("谁来救救我","周小阳",99,zyimage);
        Moment moment3=new Moment("我是大屁王！今天和周小阳跑步，好开心呀","王政文",34,wwzimage);
        Moment moment4=new Moment("嗷嗷嗷！","王政文",0,wwzhs);
        Moment moment5=new Moment("我思故我在","马小瑞",200,mr);
        dbOperate.saveMoment(moment1);
        dbOperate.saveMoment(moment2);
        dbOperate.saveMoment(moment4);
        dbOperate.saveMoment(moment3);
        dbOperate.saveMoment(moment5);
    }
}